package org.fat.nerd.actd.sharding.config.algorithm;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * <p>description</p>
 *
 * @author TanXin
 * @since 2022/2/28 17:35
 */
public class IdShardingTableAlgorithm implements PreciseShardingAlgorithm<Integer> {

    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Integer> preciseShardingValue) {
        StringBuilder sb = new StringBuilder();
        Integer value = preciseShardingValue.getValue();
        String logicTableName = preciseShardingValue.getLogicTableName();
        sb.append(logicTableName).append(value % 4);
        return sb.toString();
    }
}
